package com.tianqu.tms.www.transfer.action;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.DateUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Codes;
import com.tianqu.tms.www.transfer.viewhelper.TransferWorkCountViewHelper;

public class TransferWorkCountAddInputAction extends TmsAction {

	@SuppressWarnings("unchecked")
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		TransferWorkCountViewHelper view = (TransferWorkCountViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
		//加载下拉列表 岗位 姓名
		Codes code = Codes.getInstance();
		List codeList  = code.getCodeslistByItemId(Codes.WORK_TYPE);
		List groupList = new ArrayList();
		for(int i=0;i<codeList.size();i++)
		{
			Map map = (Map)codeList.get(i);
			String itemValue = (String)map.get("itemValue");
			Integer itemCode = (Integer)map.get("itemCode");
			if(itemCode!=1&&itemCode!=2&&itemCode!=9&&itemCode!=15&&itemCode!=19)
			{
				Map setMap = new HashMap();
				setMap.put("itemValue", itemValue);
				map.put("itemCode", map.get("itemCode"));
				groupList.add(map);
			}
		}
		view.setWorkType("");
		
		view.setWorkCount("");
		view.setGroupList(groupList);
		view.setNowDate(DateUtil.getCurrentTimeStr4());
		// 获得一个日历对象
		Calendar c = Calendar.getInstance();
		// 得到本月的那一天
		int today = c.get(c.DAY_OF_MONTH);
		view.setNdate(today);
		List daList = new ArrayList();

		for(int i=1;i<=today;i++){
			Map setMap1 = new HashMap();
			setMap1.put("xdate", i);
			daList.add(setMap1);
		}
		view.setDateList(daList);
		
		//userList载入510和480所有数据
//		User user = new User();
//		List userList = user.getUserListByRole();
//		view.setUserList(userList);
//		TmsUserProfile profile = uc.getUserProfile();
//		String userName = profile.getLoginId();
//		String str = TmsConstants.WWW_WORKCOUNT_PERMISSION;
		
//		view.setWorkType("");
//		view.setUserid("");
//		view.setWorkCount("");
//		view.setCountDay("");
		request.setAttribute(TmsConstants.VIEWHELP, view);
		return mapping.findForward(TmsConstants.SUCCESS);
	}
}
